package com.hdoit.ares.logical.acc.dao.impl;

import java.util.List;

import org.springframework.stereotype.Component;

import com.hdoit.ares.logical.acc.dao.IAccountInfoDao;
import com.hdoit.ares.logical.acc.model.AccountInfo;
import com.hdoit.ares.logical.viewmodel.acc.AccountInfoSearch;
import com.tennetcn.common.dao.base.IFinderExpression;
import com.tennetcn.common.dao.base.impl.SuperDao;
import com.tennetcn.common.enums.OrderEnum;
import com.tennetcn.common.message.PagerModel;
import com.tennetcn.common.utils.FinderExpressionFactory;
/**
 * @author      caochengmeng
 * @email       
 * @createtime  2017年11月27日 09:03:38
 * @comment
 */
@Component
public class AccountInfoDaoImpl extends SuperDao<AccountInfo> implements IAccountInfoDao{

	@Override
	public AccountInfo queryModelByCustomerId(String id) {
		IFinderExpression finderExpression=FinderExpressionFactory.createExpression();
		
		finderExpression.select("*")
						.from(AccountInfo.class)
						.andEq("customerId",id);
		
	    return queryModel(finderExpression);
	}

	@Override
	public List<AccountInfo> querListByCustomerId(String id) {
		IFinderExpression finderExpression=FinderExpressionFactory.createExpression();
		
		finderExpression.select("*")
						.from(AccountInfo.class)
						.andEq("customerId",id)
						.addOrder("account", OrderEnum.asc);
		
		return queryList(finderExpression);
	}
	
	@Override
	public List<AccountInfo> queryList(AccountInfoSearch accountInfoSearch, PagerModel pagerModel) {
		IFinderExpression finderExpression = FinderExpressionFactory.createExpression();
		
		finderExpression.select("*")
						.from(AccountInfo.class)
						.addOrder("account", OrderEnum.asc);
		
		return queryList(finderExpression, accountInfoSearch, pagerModel);
	}

	@Override
	public Double queryGoldBean(String id) {
		IFinderExpression finderExpression = FinderExpressionFactory.createExpression();
		
		finderExpression.select("goldenBean")
						.from(AccountInfo.class)
						.andEq("customerId",id);
		
		return queryModel(finderExpression).getGoldenBean();
	}

	@Override
	public Double queryAllBalance() {
		IFinderExpression finderExpression = FinderExpressionFactory.createExpression();
		
		finderExpression.select("sum(balance)")
						.from(AccountInfo.class);
		
		return querySum(finderExpression);
	}

}